# dev by mids

use strict;
use warnings;

use Dogtanian;
use LWP::Simple;
use HTML::Entities;

sub realSub {
	say "Youtube link detected, querying...";
	my $data = $&;
	
	unless ($data =~ m/^http:\/\//) {
		$data =~ s/^/http:\/\//;
	}
	
	my @content = split( "\n", get($data) ) or die "Invalid URL.";
	my $title;

	foreach (@content) {
		if (/<meta name="title" content=/) {
			$title = $_;
			$title =~ s/.*<meta name="title" content="(.*)".*/$1/i;
			last;
		}
	}
	
	say "Video entitled: ".decode_entities($title);
}

match qr/\b(http:\/\/)?youtube\.com\/watch\?v=[0-9a-zA-Z-]+/i => \&realSub;

match qr/\b(http:\/\/)?youtu\.be\/[0-9a-zA-Z-]+/i => \&realSub;